home *** CD-ROM | disk | FTP | other *** search
/ Space Shuttle - The First 100 Flights / Space Shuttle - The First 100 Flights.iso / xTras / DirectMedia Xtra Behaviors.cst / 00007_Script_Balance slider < prev    next >
Text File  |  2000-01-16  |  6KB  |  179 lines

  1. -- DirectMedia Xtra Balance Slider
  2.  
  3.  
  4.  
  5. property pDuration, pMovieTime, VideoSprite
  6.  
  7. property horizontal  -- if false, vertical
  8. property extentSprite
  9. property hiliteMember  -- looks like the handle plus hilite graphics
  10. -- also holds the member of handle while hilited
  11.  
  12. property tracking
  13. property newLocH
  14. property newLocV
  15.  
  16. property dynamic   -- if true and sending true, sends value while tracking
  17.  
  18. property min, max  -- the range the slider maps to
  19. property valrange  -- the difference of max and min, set on begin
  20. property minScreen, maxScreen -- calculated from the screen coords of the extent
  21. property currentScreenVal -- the data point in screen coords, set in tracking
  22. property extentlength -- in screen coords, set on begin
  23.  
  24. property CurrentVal
  25.  
  26. on getPropertyDescriptionList
  27.   if the currentspritenum = 0 then 
  28.     set memdefault = 0 
  29.   else
  30.     set memref = the member of sprite the currentspritenum
  31.     set memdefault = member (the membernum of member memref + 1) 
  32.   end if
  33.   
  34.   
  35.   set description = [:]
  36.   
  37.   addprop description, #VideoSprite, [#default: 1, #format:#integer, #comment: "Video Sprite:"]
  38.   
  39.   addprop description, #extentSprite, [#default: 1, #format:#integer, #comment: "Extent Sprite:"]
  40.   
  41.   addprop description, #hiliteMember, [#default: memdefault , #format:#graphic,#comment: "Hilite Member:"]
  42.   
  43.  
  44.   addprop description, #dynamic, [#default: 1, #format:#boolean,#comment: "Dynamic:"]
  45.   
  46.   return description
  47. end
  48.  
  49. on getBehaviorDescription
  50.   return "Drag to slider 'handle' to enable control of balance.  Requires additional 'extent' member which limits the handle travel range." & RETURN & "PARAMETERS:" & RETURN & "ò Video Sprite - Enter the number of sprite channel in which video is displayed." & RETURN & "ò Extent Sprite -  Enter the number of sprite channel that contains the 'extent' sprite."  & RETURN & "ò Hilite Member -  Member to display while handle is being dragged."  & RETURN &  "ò Dynamic - If set, balance will be updated while handle is dragged, else when handle is released."
  51. end
  52.  
  53. on compute_val me
  54.   -- relies on tracking to update the currentScreenVal (different for Hor, Vert)
  55.   set val = 0.0
  56.   set val = float(the currentScreenVal of me) / float (the extentlength of me)
  57.   set val = val * the valrange of me
  58.   set val = val + the min of me
  59.   return val
  60. end
  61.  
  62. on send_the_val me, val
  63.   -- sets the digital video balance to the val * paramter 
  64.   set pMovieTime = val * pDuration
  65.   setbalance(sprite VideoSprite, pMovieTime-100)
  66. end
  67.  
  68.  
  69. on beginSprite me
  70.   
  71.   set pDuration = 200
  72.   
  73.   set the min of me = 0.0
  74.   set the max of me = 1.0
  75.   
  76.   set handle = the spritenum of me
  77.   set the tracking of me = FALSE
  78.   set the newLocH of me = the locH of sprite handle
  79.   set the newLocV of me = the locV of sprite handle
  80.   
  81.  
  82.     set the newLocV of me = the locV of sprite the extentSprite of me
  83.     set the minScreen of me = the left of sprite the extentSprite of me
  84.     set the maxScreen of me = the right of sprite the extentSprite of me
  85.  
  86.   
  87.   set the locH of sprite handle to the newLocH of me
  88.   set the locV of sprite handle to the newLocV of me
  89.   
  90.   set the valrange of me = the max of me - the min of me
  91.   set the extentlength of me = the maxScreen of me - the minScreen of me
  92.   
  93.   
  94. end
  95.  
  96. on prepareFrame me
  97.  
  98.   
  99.   if tracking then
  100.     set handle = the spriteNum of me
  101.     set extent =  the extentSprite of me
  102.     
  103.  
  104.       set the newLocH of me = the mouseH
  105.       set the newLocV of me = the locV of sprite extent
  106.       if the newLocH of me < the left of sprite extent then
  107.         set the newLocH of me = the left of sprite extent
  108.       end if
  109.       if the newLocH of me > the right of sprite extent then
  110.         set the newLocH of me = the right of sprite extent
  111.       end if
  112.       
  113.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  114.       
  115.     
  116.     set the locH of sprite handle to the newLocH of me
  117.     set the locV of sprite handle to the newLocV of me
  118.     
  119.     if the dynamic of me then
  120.       send_the_val me, compute_val (me)
  121.     end if
  122.     
  123.   else   --  end if tracking, control slider position by movieTime
  124.     
  125.     set x = float(getbalance(sprite VideoSprite)+100)/ float(pDuration)
  126.     
  127.     
  128.     set handle = the spriteNum of me
  129.     set extent =  the extentSprite of me
  130.     
  131.  
  132.       set ScreenX = the left of sprite extent + (x * (the right of sprite extent - the left of sprite extent))
  133.       set the newLocH of me = screenX
  134.       set the newLocV of me = the locV of sprite extent
  135.       if the newLocH of me < the left of sprite extent then
  136.         set the newLocH of me = the left of sprite extent
  137.       end if
  138.       if the newLocH of me > the right of sprite extent then
  139.         set the newLocH of me = the right of sprite extent
  140.       end if
  141.       
  142.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  143.       
  144.     
  145.     set the locH of sprite handle to the newLocH of me
  146.     set the locV of sprite handle to the newLocV of me
  147.     
  148.   end if
  149.   
  150.   
  151. end
  152.  
  153. on mouseDown me 
  154.   set tracking = TRUE
  155.   set temp = the member of sprite the spritenum of me
  156.   set the member of sprite the spritenum of me = member the hiliteMember of me
  157.   set the hiliteMember of me = temp
  158. end
  159.  
  160. on mouseUp me
  161.   set tracking = FALSE
  162.   set temp = the member of sprite the spritenum of me
  163.   set the member of sprite the spritenum of me = member the hiliteMember of me
  164.   set the hiliteMember of me = temp
  165.     
  166. end
  167.  
  168. on mouseUpOutside me
  169.   set tracking = FALSE
  170.   set temp = the member of sprite the spritenum of me
  171.   set the member of sprite the spritenum of me = member the hiliteMember of me
  172.   set the hiliteMember of me = temp
  173.     
  174. end
  175.  
  176.  
  177.  
  178.  
  179.